package JavaSE.CODE.javaThread.Create;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class ThreadACallable implements Callable<Object> {

    @Override
    public Object call() throws Exception {
        for (int i = 0; i < 100; i++) {
            System.out.println("hhh " + i + " ;");
        }
        return null;
    }

    public static void main(String[] args) throws Exception{
        //3、创建执行对象
        ThreadACallable threadACallable1 = new ThreadACallable();
        ThreadACallable threadACallable2 = new ThreadACallable();
        ThreadACallable threadACallable3 = new ThreadACallable();
        //4、创建执行服务 建池
        ExecutorService service = Executors.newFixedThreadPool(3);
        //5、提交执行
        Future<Object> r1 = service.submit(threadACallable1);
        Future<Object> r2 = service.submit(threadACallable2);
        Future<Object> r3 = service.submit(threadACallable3);

        //6、获取结果
        Object rs1 = r1.get();
        Object rs2 = r2.get();
        Object rs3 = r3.get();

        //7、关闭服务
        service.shutdown();
    }
}
